<?php
/*
	管理端链接获取接口
*/
defined('BY_JYA') or exit('error');
$return=array();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'system';
$tabs=array(
	array('op'=>'system','title'=>'系统页面'),
	array('op'=>'diy','title'=>'DIY页面'),
);
if($_RQ['op']=='system'){
	$return['list']=get_wxapp_pages();
	foreach($return['list'] as $k=>&$item){
		$item['apppath']=wxapp_links($item['url']);
	}
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'pagelist'=>false,'list'=>array(
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'url','title'=>'H5路径','type'=>'string'),
			array('name'=>'apppath','title'=>'小程序路径','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='diy'){
	$pindex=max(1,intval($_RQ['page']));
	$psize=10;
	$params=array('uniacid'=>0,'type'=>0);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$total=0;
	$fields=array('id','title','createtime');
	$list=pdo_getslice('core_mobile_web',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('y/m/d H:i:s',$item['createtime']);
			$item['url']=manage_url('core/home.diy/main/id='.$item['id']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'tip'=>'这里只显示DIY页面（系统页面，头部，底部等类型页面不显示）！','list'=>array(
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
?>

